home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-19 / iritsm3s.zip / CAGD_LIB.H < prev    next >
C/C++ Source or Header  |  1992-01-28  |  25KB  |  524 lines

  1. /******************************************************************************
  2. * Cagd_lib.h - header file for the CAGD library.                  *
  3. * This header is also the interface header to the world.              *
  4. *******************************************************************************
  5. * Written by Gershon Elber, Mar. 90.                          *
  6. ******************************************************************************/
  7.  
  8. #ifndef CAGD_LIB_H
  9. #define CAGD_LIB_H
  10.  
  11. #include <stdio.h>
  12.  
  13. #ifdef NO_VOID_PTR
  14. #define VoidPtr        char *
  15. #else
  16. #define VoidPtr        void *
  17. #endif /* NO_VOID_PTR */
  18.  
  19. #define CagdBType int                              /* Boolean type. */
  20. #ifdef __MSDOS__
  21. typedef float CagdRType;
  22. #define CAGD_FLOAT
  23. #else
  24. typedef double CagdRType;
  25. #define CAGD_DOUBLE
  26. #endif /* __MSDOS__ */
  27.  
  28. typedef void (*CagdPrintfFuncType)(char *Line);
  29.  
  30. typedef enum {
  31.     CAGD_ERR_UNDEFINE_ERR,
  32.     CAGD_ERR_180_ARC,
  33.     CAGD_ERR_PT_OR_LEN_MISMATCH,
  34.     CAGD_ERR_CRVS_INCOMPATIBLE,
  35.     CAGD_ERR_RAT_LIN_NO_SUPPORT,
  36.     CAGD_ERR_DIR_NOT_CONST_UV,
  37.     CAGD_ERR_T_NOT_IN_CRV,
  38.     CAGD_ERR_U_NOT_IN_SRF,
  39.     CAGD_ERR_V_NOT_IN_SRF,
  40.     CAGD_ERR_INDEX_NOT_IN_MESH,
  41.     CAGD_ERR_NUM_KNOT_MISMATCH,
  42.     CAGD_ERR_PARSER_STACK_OV,
  43.     CAGD_ERR_KNOT_NOT_ORDERED,
  44.     CAGD_ERR_UNDEF_CRV,
  45.     CAGD_ERR_UNDEF_SRF,
  46.     CAGD_ERR_UNSUPPORT_PT,
  47.     CAGD_ERR_POWER_NO_SUPPORT,
  48.     CAGD_ERR_ALLOC_ERR,
  49.     CAGD_ERR_NOT_ENOUGH_MEM,
  50.     CAGD_ERR_NOT_IMPLEMENTED,
  51.     CAGD_ERR_WRONG_ORDER
  52. } CagdFatalErrorType;
  53.  
  54. typedef enum {        /* Type of control point. The P-types are rationals. */
  55.     CAGD_PT_E1_TYPE = 0,
  56.     CAGD_PT_P1_TYPE,
  57.     CAGD_PT_E2_TYPE,
  58.     CAGD_PT_P2_TYPE,
  59.     CAGD_PT_E3_TYPE,
  60.     CAGD_PT_P3_TYPE,
  61.     CAGD_PT_E4_TYPE,
  62.     CAGD_PT_P4_TYPE,
  63.     CAGD_PT_E5_TYPE,
  64.     CAGD_PT_P5_TYPE
  65. } CagdPointType;
  66.  
  67. #define CAGD_IS_RATIONAL_PT(PType)    (((int) PType) & 0x01)
  68. #define CAGD_NUM_OF_PT_COORD(PType)    ((((int) PType) >> 1) + 1)
  69. #define CAGD_MAKE_PT_TYPE(IsRational, NumCoords) ((CagdPointType) \
  70.                           ((((IsRational) ? -1 : -2) \
  71.                             + (NumCoords << 1))))
  72. #define CAGD_MAX_PT_SIZE        6    /* Rational P5 has 6 coords. */
  73. #define CAGD_MAX_PT_COORD        5               /* Without w. */
  74.  
  75. #define CAGD_IS_RATIONAL_CRV(Crv)    CAGD_IS_RATIONAL_PT(Crv -> PType)
  76. #define CAGD_IS_RATIONAL_SRF(Srf)    CAGD_IS_RATIONAL_PT(Srf -> PType)
  77.  
  78. /* Bezier curves may be evaluated using a predefined cache. The cache must   */
  79. /* be of size (FINENESS) which is power of 2 up to the maximum order below.  */
  80. /* See CrvBzrSetCache routine below.                         */
  81. #define CAGD_MAX_BEZIER_CACHE_ORDER    10
  82. #define CAGD_MAX_BEZIER_CACHE_FINENESS    1024
  83.  
  84. typedef enum {
  85.     CAGD_UNDEF_TYPE,
  86.     CAGD_CBEZIER_TYPE,
  87.     CAGD_CBSPLINE_TYPE,
  88.     CAGD_CPOWER_TYPE,
  89.     CAGD_SBEZIER_TYPE,
  90.     CAGD_SBSPLINE_TYPE,
  91.     CAGD_SPOWER_TYPE
  92. } CagdGeomType;
  93.  
  94. typedef enum {
  95.     CAGD_NO_DIR,
  96.     CAGD_CONST_U_DIR,
  97.     CAGD_CONST_V_DIR
  98. } CagdSrfDirType;
  99.  
  100. typedef enum {
  101.     CAGD_REG_POLY_PER_LIN,
  102.     CAGD_ONE_POLY_PER_LIN,
  103.     CAGD_ONE_POLY_PER_COLIN
  104. } CagdLin2PolyType;
  105.  
  106. typedef struct CagdPtStruct {
  107.     CagdRType Pt[3];
  108. } CagdPtStruct;
  109.  
  110. typedef struct CagdCtlPtStruct {
  111.     CagdPointType PtType;
  112.     CagdRType Coords[CAGD_MAX_PT_SIZE];
  113. } CagdCtlPtStruct;
  114.  
  115. typedef struct CagdVecStruct {
  116.     CagdRType Vec[3];
  117. } CagdVecStruct;
  118.  
  119. typedef struct CagdPlaneStruct {
  120.     CagdRType Plane[4];
  121. } CagdPlaneStruct;
  122.  
  123. typedef struct CagdMatStruct {
  124.     CagdRType Mat[4][4];
  125. } CagdMatStruct;
  126.  
  127. typedef struct CagdBBoxStruct {
  128.     CagdRType Min[3];
  129.     CagdRType Max[3];
  130. } CagdBBoxStruct;
  131.  
  132. typedef struct CagdCrvStruct {
  133.     struct CagdCrvStruct *Pnext;
  134.     CagdGeomType GType;
  135.     CagdPointType PType;
  136.     int Length;            /* Number of control points (== order in Bezier). */
  137.     int Order;        /* Order of curve (only for Bspline, ignored in Bezier). */
  138.     CagdRType *Points[CAGD_MAX_PT_SIZE];     /* Pointer on each axis vector. */
  139.     CagdRType *KnotVector;
  140. } CagdCrvStruct;
  141.  
  142. typedef struct CagdSrfStruct {
  143.     struct CagdSrfStruct *Pnext;
  144.     CagdGeomType GType;
  145.     CagdPointType PType;
  146.     int ULength, VLength;     /* Mesh size in the tensor product surface. */
  147.     int UOrder, VOrder;   /* Order in tensor product surface (Bspline only). */
  148.     CagdRType *Points[CAGD_MAX_PT_SIZE];     /* Pointer on each axis vector. */
  149.     CagdRType *UKnotVector, *VKnotVector;
  150. } CagdSrfStruct;
  151.  
  152. typedef struct CagdPolygonStruct {
  153.     struct CagdPolygonStruct *Pnext;
  154.     CagdPtStruct Polygon[3];              /* Polygon is always triangle. */
  155.     CagdVecStruct Normal[3];
  156. } CagdPolygonStruct;
  157.  
  158. typedef struct CagdPolylineStruct {
  159.     struct CagdPolylineStruct *Pnext;
  160.     CagdPtStruct *Polyline;         /* Polyline length is defined using Length. */
  161.     int Length;
  162. } CagdPolylineStruct;
  163.  
  164. #define CAGD_IS_BEZIER_CRV(Crv)        (Crv -> GType == CAGD_CBEZIER_TYPE)
  165. #define CAGD_IS_BEZIER_SRF(Srf)        (Srf -> GType == CAGD_SBEZIER_TYPE)
  166. #define CAGD_IS_BSPLINE_CRV(Crv)    (Crv -> GType == CAGD_CBSPLINE_TYPE)
  167. #define CAGD_IS_BSPLINE_SRF(Srf)    (Srf -> GType == CAGD_SBSPLINE_TYPE)
  168. #define CAGD_IS_POWER_CRV(Crv)        (Crv -> GType == CAGD_CPOWER_TYPE)
  169. #define CAGD_IS_POWER_SRF(Srf)        (Srf -> GType == CAGD_SPOWER_TYPE)
  170.  
  171. /******************************************************************************
  172. *        U -->                The mesh is ordered raw after raw *
  173. *       +-----------------------+    or the increments along U are 1 while *
  174. *   V | |P0                 Pi-1|    the increment along V is full raw.    *
  175. *     v    |Pi                P2i-1|        To encapsulate it, NEXTU/V are    *
  176. *    |            |    defined below.                  *
  177. *    |Pn-i            Pn-1|                          *
  178. *    +-----------------------+                          *
  179. ******************************************************************************/
  180. #define CAGD_NEXT_U(Srf)    (1)
  181. #define CAGD_NEXT_V(Srf)    (Srf -> ULength)
  182. #define CAGD_MESH_UV(Srf, i, j)    ((i) + (Srf -> ULength) * (j))
  183.  
  184. /******************************************************************************
  185. * Routines prototypes. Routines are prefixed as follows:              *
  186. * Cagd    - General routines such as dynamic memory handlers etc.          *
  187. * BzrCrv  - Bezier curves routines.                          *
  188. * BzrSrf  - Bezier surface routines.                          *
  189. * BspKnot - Bspline knot vector routines.                      *
  190. * BspCrv  - Bspline curves routines.                          *
  191. * BspSrf  - Bspline surface routines.                          *
  192. * Cnvrt   - Conversion routines such as Bezier to Power basis.              *
  193. ******************************************************************************/
  194.  
  195. #if defined(__cplusplus) || defined(c_plusplus)
  196. extern "C" {
  197. #endif
  198.  
  199. /******************************************************************************
  200. * General routines of the Cagd library:                          *
  201. ******************************************************************************/
  202. CagdCrvStruct *CagdCrvNew(CagdGeomType GType, CagdPointType PType, int Length);
  203. CagdSrfStruct *CagdSrfNew(CagdGeomType GType, CagdPointType PType, int ULength,
  204.                                    int VLength);
  205. CagdPolygonStruct *CagdPolygonNew(void);
  206. CagdPolylineStruct *CagdPolylineNew(int Length);
  207. CagdCrvStruct *CagdCrvCopy(CagdCrvStruct *Crv);
  208. CagdSrfStruct *CagdSrfCopy(CagdSrfStruct *Srf);
  209. CagdPolygonStruct *CagdPolygonCopy(CagdPolygonStruct *Poly);
  210. CagdPolylineStruct *CagdPolylineCopy(CagdPolylineStruct *Poly);
  211. void CagdCrvFree(CagdCrvStruct *Crv);
  212. void CagdCrvFreeList(CagdCrvStruct *CrvList);
  213. void CagdSrfFree(CagdSrfStruct *Srf);
  214. void CagdSrfFreeList(CagdSrfStruct *SrfList);
  215. void CagdPolylineFree(CagdPolylineStruct *Poly);
  216. void CagdPolylineFreeList(CagdPolylineStruct *PolyList);
  217. void CagdPolygonFree(CagdPolygonStruct *Poly);
  218. void CagdPolygonFreeList(CagdPolygonStruct *PolyList);
  219. void CagdCoerceToE2(CagdRType *E2Point, CagdRType *Points[CAGD_MAX_PT_SIZE],
  220.                          int Index, CagdPointType PType);
  221. void CagdCoerceToE3(CagdRType *E3Point, CagdRType *Points[CAGD_MAX_PT_SIZE],
  222.                          int Index, CagdPointType PType);
  223. void CagdCoerceToP2(CagdRType *P2Point, CagdRType *Points[CAGD_MAX_PT_SIZE],
  224.                          int Index, CagdPointType PType);
  225. void CagdCoerceToP3(CagdRType *P3Point, CagdRType *Points[CAGD_MAX_PT_SIZE],
  226.                          int Index, CagdPointType PType);
  227. void CagdCoercePointsTo(CagdRType *Points[], int Len,
  228.             CagdPointType OldPType, CagdPointType NewPType);
  229. CagdCrvStruct *CagdCoerceCrvTo(CagdCrvStruct *Crv, CagdPointType PType);
  230. CagdSrfStruct *CagdCoerceSrfTo(CagdSrfStruct *Srf, CagdPointType PType);
  231. CagdPointType CagdMergePointType(CagdPointType PType1, CagdPointType PType2);
  232. VoidPtr CagdMalloc(unsigned size);
  233. void CagdFree(VoidPtr p);
  234. void CagdFatalError(CagdFatalErrorType ErrID);
  235. char *CagdDescribeError(CagdFatalErrorType ErrID);
  236. void CagdDbg(void *Obj);
  237. void CagdSetCagdFprintf(CagdPrintfFuncType Func);
  238. void CagdSetLinear2Poly(CagdLin2PolyType Lin2Poly);
  239. void CagdMergeBBox(CagdBBoxStruct *DestBBox, CagdBBoxStruct *SrcBBox);
  240.  
  241. /******************************************************************************
  242. * Matrix/Vector/Plane/Transformation routines:                      *
  243. ******************************************************************************/
  244. CagdRType CagdDistanceTwoCtlPts(CagdRType **Points, int Index1, int Index2,
  245.                             CagdPointType PType);
  246. CagdRType CagdFitPlaneThruCtlPts(CagdPlaneStruct *Plane, CagdPointType PType,
  247.                      CagdRType **Points,
  248.                      int Index1, int Index2, int Index3, int Index4);
  249. CagdRType CagdDistPtPlane(CagdPlaneStruct *Plane, CagdRType **Points,
  250.                               int Index, int MaxDim);
  251.  
  252. void CagdMultMatVec(CagdMatStruct *Mat, CagdRType *SrcVec, CagdRType *DstVec);
  253. void CagdCrvMatTransform(CagdCrvStruct *Crv, CagdMatStruct *Mat);
  254. void CagdSrfMatTransform(CagdSrfStruct *Srf, CagdMatStruct *Mat);
  255. void CagdCrvTransform(CagdCrvStruct *Crv, CagdRType Translate[3],
  256.                             CagdRType Scale);
  257. void CagdSrfTransform(CagdSrfStruct *Srf, CagdRType Translate[3],
  258.                             CagdRType Scale);
  259.  
  260. /******************************************************************************
  261. * Routines to handle curves generically.                      *
  262. ******************************************************************************/
  263. CagdRType CagdEstimateCrvColinearity(CagdCrvStruct *Crv);
  264. CagdRType *CagdCrvEval(CagdCrvStruct *Crv, CagdRType t);
  265. CagdCrvStruct *CagdCrvSubdivAtParam(CagdCrvStruct *Crv, CagdRType t);
  266. CagdCrvStruct *CagdCrvRegionFromCrv(CagdCrvStruct *Crv, CagdRType t1,
  267.                             CagdRType t2);
  268. CagdCrvStruct *CagdCrvRefineAtParams(CagdCrvStruct *Crv, CagdBType Replace,
  269.                              CagdRType *t, int n);
  270. CagdVecStruct *CagdCrvTangent(CagdCrvStruct *Crv, CagdRType t);
  271. CagdVecStruct *CagdCrvBiNormal(CagdCrvStruct *Crv, CagdRType t);
  272. CagdVecStruct *CagdCrvNormal(CagdCrvStruct *Crv, CagdRType t);
  273. CagdCrvStruct *CagdCrvOffset(CagdCrvStruct *Crv, CagdRType OffsetDist);
  274. CagdCrvStruct *CagdCrvReverse(CagdCrvStruct *Crv);
  275. CagdCrvStruct *CagdCrvDegreeRaise(CagdCrvStruct *Crv);
  276. CagdCrvStruct *CagdMergeCrvCrv(CagdCrvStruct *Crv1, CagdCrvStruct *Crv2);
  277. CagdCrvStruct *CagdMergeCrvPt(CagdCrvStruct *Crv, CagdPtStruct *Pt);
  278. CagdCrvStruct *CagdMergePtCrv(CagdPtStruct *Pt, CagdCrvStruct *Crv);
  279. CagdCrvStruct *CagdMergePtPt(CagdPtStruct *Pt1, CagdPtStruct *Pt2);
  280. CagdPolylineStruct *CagdCrv2CtrlPoly(CagdCrvStruct *Crv);
  281. CagdPolylineStruct *CagdCrv2Polyline(CagdCrvStruct *Crv, int SamplesPerCurve);
  282. CagdBType CagdMakeCrvsCompatible(CagdCrvStruct **Crv1, CagdCrvStruct **Crv2,
  283.                  CagdBType SameOrder, CagdBType SameKV);
  284. CagdCrvStruct *CagdEditSingleCrvPt(CagdCrvStruct *Crv, CagdCtlPtStruct *CtlPt,
  285.                                    int Index);
  286. CagdCrvStruct *CagdCrvReadFromFile(char *FileName, char **ErrStr, int *Line);
  287. CagdCrvStruct *CagdCrvReadFromFile2(FILE *f, char **ErrStr, int *Line);
  288. int CagdCrvWriteToFile(CagdCrvStruct *Crvs, char *FileName, int Indent,
  289.                          char *Comment,    char **ErrStr);
  290. int CagdCrvWriteToFile2(CagdCrvStruct *Crvs, FILE *f, int Indent, char *Comment,
  291.                                 char **ErrStr);
  292. void CagdCrvBBox(CagdCrvStruct *Crv, CagdBBoxStruct *BBox);
  293.  
  294. /******************************************************************************
  295. * Routines to handle surfaces generically.                      *
  296. ******************************************************************************/
  297. CagdRType CagdEstimateSrfPlanarity(CagdSrfStruct *Srf);
  298. CagdRType *CagdSrfEval(CagdSrfStruct *Srf, CagdRType u, CagdRType v);
  299. CagdCrvStruct *CagdCrvFromSrf(CagdSrfStruct *Srf, CagdRType t,
  300.                             CagdSrfDirType Dir);
  301. CagdCrvStruct *CagdCrvFromMesh(CagdSrfStruct *Srf, int Index,
  302.                             CagdSrfDirType Dir);
  303. void CagdCrvToMesh(CagdCrvStruct *Crv, int Index,
  304.                     CagdSrfDirType Dir, CagdSrfStruct *Srf);
  305. CagdSrfStruct *CagdSrfSubdivAtParam(CagdSrfStruct *Srf, CagdRType t,
  306.                                 CagdSrfDirType Dir);
  307. CagdSrfStruct *CagdSrfRegionFromSrf(CagdSrfStruct *Srf, CagdRType t1,
  308.                          CagdRType t2, CagdSrfDirType Dir);
  309. CagdSrfStruct *CagdSrfRefineAtParams(CagdSrfStruct *Srf, CagdSrfDirType Dir,
  310.                     CagdBType Replace, CagdRType *t, int n);
  311. CagdVecStruct *CagdSrfTangent(CagdSrfStruct *Srf, CagdRType u, CagdRType v,
  312.                                 CagdSrfDirType Dir);
  313. CagdVecStruct *CagdSrfNormal(CagdSrfStruct *Srf, CagdRType u, CagdRType v);
  314. CagdSrfStruct *CagdSrfOffset(CagdSrfStruct *Srf, CagdRType OffsetDist);
  315. CagdSrfStruct *CagdSrfDegreeRaise(CagdSrfStruct *Srf, CagdSrfDirType Dir);
  316. CagdSrfStruct *CagdSrfReverse(CagdSrfStruct *Srf);
  317. CagdSrfStruct *CagdSrfReverse2(CagdSrfStruct *Srf);
  318. CagdPolylineStruct *CagdSrf2CtrlMesh(CagdSrfStruct *Srf);
  319. CagdPolygonStruct *CagdSrf2Polygons(CagdSrfStruct *Srf, int FineNess,
  320.                   CagdBType ComputeNormals, CagdBType FourPerFlat);
  321. CagdPolylineStruct *CagdSrf2Polylines(CagdSrfStruct *Srf, int NumOfIsocurves,
  322.                               int SamplesPerCurve);
  323. CagdSrfStruct *CagdSrfReadFromFile(char *FileName, char **ErrStr, int *Line);
  324. CagdSrfStruct *CagdSrfReadFromFile2(FILE *f, char **ErrStr, int *Line);
  325. int CagdSrfWriteToFile(CagdSrfStruct *Srfs, char *FileName, int Indent,
  326.                          char *Comment,    char **ErrStr);
  327. int CagdSrfWriteToFile2(CagdSrfStruct *Srfs, FILE *f, int Indent, char *Comment,
  328.                                 char **ErrStr);
  329. CagdSrfStruct *CagdExtrudeSrf(CagdCrvStruct *Crv, CagdVecStruct *Vec);
  330. CagdSrfStruct *CagdSurfaceRev(CagdCrvStruct *Crv);
  331. CagdSrfStruct *CagdSweepSrf(CagdCrvStruct *CrossSection, CagdCrvStruct *Axis,
  332.                     CagdCrvStruct *ScalingCrv, CagdRType Scale);
  333. CagdSrfStruct *CagdBoolSumSrf(CagdCrvStruct *CrvLeft,
  334.                   CagdCrvStruct *CrvRight,
  335.                   CagdCrvStruct *CrvTop,
  336.                   CagdCrvStruct *CrvBottom);
  337. CagdSrfStruct *CagdRuledSrf(CagdCrvStruct *Crv1, CagdCrvStruct *Crv2,
  338.                 int OtherOrder, int OtherLen);
  339. CagdSrfStruct *CagdSrfFromCrvs(CagdCrvStruct *CrvList);
  340. CagdSrfStruct *CagdEditSingleSrfPt(CagdSrfStruct *Srf, CagdCtlPtStruct *CtlPt,
  341.                                int UIndex, int VIndex);
  342. void CagdSrfBBox(CagdSrfStruct *Srf, CagdBBoxStruct *BBox);
  343.  
  344. /******************************************************************************
  345. * Routines to handle Bezier curves.                          *
  346. ******************************************************************************/
  347. CagdCrvStruct *BzrCrvReadFromFile(char *FileName, char **ErrStr, int *ErrLine);
  348. CagdCrvStruct *BzrCrvReadFromFile2(FILE *f, CagdBType NameWasRead,
  349.                           char **ErrStr, int *ErrLine);
  350. int BzrCrvWriteToFile(CagdCrvStruct *Crvs, char *FileName, int Indent,
  351.                          char *Comment,    char **ErrStr);
  352. int BzrCrvWriteToFile2(CagdCrvStruct *Crvs, FILE *f, int Indent, char *Comment,
  353.                                 char **ErrStr);
  354. CagdCrvStruct *BzrCrvNew(int Length, CagdPointType PType);
  355. CagdRType BzrCrvEvalVecAtParam(CagdRType *Vec, int VecInc, int Order,
  356.                                 CagdRType t);
  357. CagdRType *BzrCrvEvalAtParam(CagdCrvStruct *Crv, CagdRType t);
  358. void BzrCrvSetCache(int FineNess, CagdBType EnableCache);
  359. void BzrCrvEvalToPolyline(CagdCrvStruct *Crv, int FineNess,
  360.                              CagdRType *Points[]);
  361. CagdCrvStruct *BzrCrvCreateArc(CagdPtStruct *Start, CagdPtStruct *Center,
  362.                                  CagdPtStruct *End);
  363. CagdCrvStruct *BzrCrvSubdivAtParam(CagdCrvStruct *Crv, CagdRType t);
  364. CagdCrvStruct *BzrCrvDegreeRaise(CagdCrvStruct *Crv);
  365. CagdCrvStruct *BzrCrvDerive(CagdCrvStruct *Crv);
  366. CagdVecStruct *BzrCrvTangent(CagdCrvStruct *Crv, CagdRType t);
  367. CagdVecStruct *BzrCrvBiNormal(CagdCrvStruct *Crv, CagdRType t);
  368. CagdVecStruct *BzrCrvNormal(CagdCrvStruct *Crv, CagdRType t);
  369. CagdCrvStruct *BzrCrvInterpolate(int Size, CagdRType *XVec, CagdRType *YVec,
  370.                                    CagdRType *ZVec);
  371. CagdPolylineStruct *BzrCrv2Polyline(CagdCrvStruct *Crv, int SamplesPerCurve);
  372.  
  373. /******************************************************************************
  374. * Routines to handle Bezier surfaces.                          *
  375. ******************************************************************************/
  376. CagdSrfStruct *BzrSrfReadFromFile(char *FileName, char **ErrStr, int *ErrLine);
  377. CagdSrfStruct *BzrSrfReadFromFile2(FILE *f, CagdBType NameWasRead,
  378.                           char **ErrStr, int *ErrLine);
  379. int BzrSrfWriteToFile(CagdSrfStruct *Srfs, char *FileName, int Indent,
  380.                          char *Comment,    char **ErrStr);
  381. int BzrSrfWriteToFile2(CagdSrfStruct *Srfs, FILE *f, int Indent, char *Comment,
  382.                                 char **ErrStr);
  383. CagdSrfStruct *BzrSrfNew(int ULength, int VLength, CagdPointType PType);
  384. CagdRType *BzrSrfEvalAtParam(CagdSrfStruct *Srf, CagdRType u, CagdRType v);
  385. CagdCrvStruct *BzrSrfCrvFromSrf(CagdSrfStruct *Srf, CagdRType t,
  386.                             CagdSrfDirType Dir);
  387. CagdCrvStruct *BzrSrfCrvFromMesh(CagdSrfStruct *Srf, int Index,
  388.                             CagdSrfDirType Dir);
  389. CagdSrfStruct *BzrSrfSubdivAtParam(CagdSrfStruct *Srf, CagdRType t,
  390.                             CagdSrfDirType Dir);
  391. CagdSrfStruct *BzrSrfDegreeRaise(CagdSrfStruct *Srf, CagdSrfDirType Dir);
  392. CagdSrfStruct *BzrSrfDerive(CagdSrfStruct *Srf, CagdSrfDirType Dir);
  393. CagdVecStruct *BzrSrfTangent(CagdSrfStruct *Srf, CagdRType u, CagdRType v,
  394.                              CagdSrfDirType Dir);
  395. CagdVecStruct *BzrSrfNormal(CagdSrfStruct *Srf, CagdRType u, CagdRType v);
  396. CagdPolygonStruct *BzrSrf2Polygons(CagdSrfStruct *Srf, int FineNess,
  397.              CagdBType ComputeNormals, CagdBType FourPerFlat);
  398. CagdPolylineStruct *BzrSrf2Polylines(CagdSrfStruct *Srf, int NumOfIsocurves,
  399.                             int SamplesPerCurve);
  400.  
  401. /******************************************************************************
  402. * Routines to handle Bspline knot vectors.                      *
  403. ******************************************************************************/
  404. CagdBType BspKnotHasOpenEC(CagdRType *KnotVector, int Len, int Order);
  405. CagdBType BspKnotParamInDomain(CagdRType *KnotVector, int Len, int Order,
  406.                                 CagdRType t);
  407. int BspKnotLastIndexLE(CagdRType *KnotVector, int Len, CagdRType t);
  408. int BspKnotLastIndexL(CagdRType *KnotVector, int Len, CagdRType t);
  409. int BspKnotFirstIndexG(CagdRType *KnotVector, int Len, CagdRType t);
  410. CagdRType *BspKnotUniformFloat(int Len, int Order, CagdRType *KnotVector);
  411. CagdRType *BspKnotUniformOpen(int Len, int Order, CagdRType *KnotVector);
  412. CagdRType *BspKnotSubtrTwo(CagdRType *KnotVector1, int Len1,
  413.                CagdRType *KnotVector2, int Len2,
  414.                int *NewLen);
  415. CagdRType *BspKnotMergeTwo(CagdRType *KnotVector1, int Len1,
  416.                CagdRType *KnotVector2, int Len2,
  417.                int Mult, int *NewLen);
  418. CagdRType *BspKnotNodes(CagdRType *KnotVector, int Len, int Order);
  419. CagdRType *BspKnotReverse(CagdRType *KnotVector, int Len);
  420. void BspKnotAffineTrans(CagdRType *KnotVector, int Len,
  421.                     CagdRType Translate, CagdRType Scale);
  422. CagdRType *BspKnotCopy(CagdRType *KnotVector, int Len);
  423. CagdRType *BspKnotInsertOne(CagdRType *KnotVector, int Order, int Len,
  424.                                 CagdRType t);
  425. CagdRType *BspKnotInsertMult(CagdRType *KnotVector, int Order, int *Len,
  426.                                CagdRType t, int Mult);
  427. int BspKnotFindMult(CagdRType *KnotVector, int Order, int Len, CagdRType t);
  428. CagdBType BspKnotC1Discont(CagdRType *KnotVector, int Order, int Length,
  429.                                 CagdRType *t);
  430. CagdRType *BspKnotAllC1Discont(CagdRType *KnotVector, int Order, int Length,
  431.                                        int *n);
  432. CagdRType *BspKnotParamValues(CagdRType PMin, CagdRType PMax, int NumSamples,
  433.                   CagdRType *C1Disconts, int NumC1Disconts);
  434.  
  435. /******************************************************************************
  436. * Routines to handle Bspline curves.                          *
  437. ******************************************************************************/
  438. CagdCrvStruct *BspCrvReadFromFile(char *FileName, char **ErrStr, int *ErrLine);
  439. CagdCrvStruct *BspCrvReadFromFile2(FILE *f, CagdBType NameWasRead,
  440.                           char **ErrStr, int *ErrLine);
  441. int BspCrvWriteToFile(CagdCrvStruct *Crvs, char *FileName, int Indent,
  442.                          char *Comment,    char **ErrStr);
  443. int BspCrvWriteToFile2(CagdCrvStruct *Crvs, FILE *f, int Indent, char *Comment,
  444.                                 char **ErrStr);
  445. CagdCrvStruct *BspCrvNew(int Length, int Order, CagdPointType PType);
  446. void BspCrvDomain(CagdCrvStruct *Crv, CagdRType *TMin, CagdRType *TMax);
  447.  
  448. CagdRType *BspCrvCoxDeBoorBasis(CagdRType *KnotVector, int Order, int Len,
  449.                         CagdRType t, int *IndexFirst);
  450. CagdRType *BspCrvEvalCoxDeBoor(CagdCrvStruct *Crv, CagdRType t);
  451. CagdRType BspCrvEvalVecAtParam(CagdRType *Vec, int VecInc,
  452.                    CagdRType *KnotVector, int Order, int Len,
  453.                    CagdRType t);
  454. CagdRType *BspCrvEvalAtParam(CagdCrvStruct *Crv, CagdRType t);
  455. CagdCrvStruct *BspCrvCreateCircle(CagdPtStruct *Center, CagdRType Radius);
  456. CagdCrvStruct *BspCrvCreateUnitCircle(void);
  457. int BspCrvEvalToPolyline(CagdCrvStruct *Crv, int FineNess, CagdRType *Points[]);
  458. CagdCrvStruct *BspCrvKnotInsert(CagdCrvStruct *Crv, CagdRType t);
  459. CagdCrvStruct *BspCrvKnotInsertNSame(CagdCrvStruct *Crv, CagdRType t, int n);
  460. CagdCrvStruct *BspCrvKnotInsertNDiff(CagdCrvStruct *Crv, CagdBType Replace,
  461.                                CagdRType *t, int n);
  462. CagdCrvStruct *BspCrvSubdivAtParam(CagdCrvStruct *Crv, CagdRType t);
  463. CagdCrvStruct *BspCrvDegreeRaise(CagdCrvStruct *Crv);
  464. CagdCrvStruct *BspCrvDerive(CagdCrvStruct *Crv);
  465. CagdVecStruct *BspCrvTangent(CagdCrvStruct *Crv, CagdRType t);
  466. CagdVecStruct *BspCrvBiNormal(CagdCrvStruct *Crv, CagdRType t);
  467. CagdVecStruct *BspCrvNormal(CagdCrvStruct *Crv, CagdRType t);
  468. CagdPolylineStruct *BspCrv2Polyline(CagdCrvStruct *Crv, int SamplesPerCurve);
  469.  
  470. /******************************************************************************
  471. * Routines to handle Bspline surfaces.                          *
  472. ******************************************************************************/
  473. CagdSrfStruct *BspSrfReadFromFile(char *FileName, char **ErrStr, int *ErrLine);
  474. CagdSrfStruct *BspSrfReadFromFile2(FILE *f, CagdBType NameWasRead,
  475.                           char **ErrStr, int *ErrLine);
  476. int BspSrfWriteToFile(CagdSrfStruct *Srfs, char *FileName, int Indent,
  477.                          char *Comment,    char **ErrStr);
  478. int BspSrfWriteToFile2(CagdSrfStruct *Srfs, FILE *f, int Indent, char *Comment,
  479.                                 char **ErrStr);
  480. CagdSrfStruct *BspSrfNew(int ULength, int VLength,
  481.              int UOrder, int VOrder, CagdPointType PType);
  482. void BspSrfDomain(CagdSrfStruct *Srf, CagdRType *UMin, CagdRType *UMax,
  483.                       CagdRType *VMin, CagdRType *VMax);
  484. CagdRType *BspSrfEvalAtParam(CagdSrfStruct *Srf, CagdRType u, CagdRType v);
  485. CagdCrvStruct *BspSrfCrvFromSrf(CagdSrfStruct *Srf, CagdRType t,
  486.                             CagdSrfDirType Dir);
  487. CagdCrvStruct *BspSrfCrvFromMesh(CagdSrfStruct *Srf, int Index,
  488.                             CagdSrfDirType Dir);
  489. CagdSrfStruct *BspSrfKnotInsert(CagdSrfStruct *BspSrf, CagdSrfDirType Dir,
  490.                                    CagdRType t);
  491. CagdSrfStruct *BspSrfKnotInsertNSame(CagdSrfStruct *BspSrf, CagdSrfDirType Dir,
  492.                                 CagdRType t, int n);
  493. CagdSrfStruct *BspSrfKnotInsertNDiff(CagdSrfStruct *BspSrf, CagdSrfDirType Dir,
  494.                           int Replace, CagdRType *t, int n);
  495. CagdSrfStruct *BspSrfSubdivAtParam(CagdSrfStruct *Srf, CagdRType t,
  496.                             CagdSrfDirType Dir);
  497. CagdSrfStruct *BspSrfDegreeRaise(CagdSrfStruct *Srf, CagdSrfDirType Dir);
  498. CagdSrfStruct *BspSrfDerive(CagdSrfStruct *Srf, CagdSrfDirType Dir);
  499. CagdVecStruct *BspSrfTangent(CagdSrfStruct *Srf, CagdRType u, CagdRType v,
  500.                              CagdSrfDirType Dir);
  501. CagdVecStruct *BspSrfNormal(CagdSrfStruct *Srf, CagdRType u, CagdRType v);
  502. CagdVecStruct *BspSrfMeshNormals(CagdSrfStruct *Srf, int UFineNess,
  503.                                 int VFineNess);
  504. CagdPolygonStruct *BspSrf2Polygons(CagdSrfStruct *Srf, int FineNess,
  505.              CagdBType ComputeNormals, CagdBType FourPerFlat);
  506. CagdPolylineStruct *BspSrf2Polylines(CagdSrfStruct *Srf, int NumOfIsocurves,
  507.                             int SamplesPerCurve);
  508.  
  509. /******************************************************************************
  510. * Routines to handle basis function conversions.                  *
  511. ******************************************************************************/
  512. CagdCrvStruct *CnvrtPower2BezierCrv(CagdCrvStruct *Crv);
  513. CagdCrvStruct *CnvrtBezier2PowerCrv(CagdCrvStruct *Crv);
  514. CagdCrvStruct *CnvrtBspline2BezierCrv(CagdCrvStruct *Crv);
  515. CagdCrvStruct *CnvrtBezier2BsplineCrv(CagdCrvStruct *Crv);
  516.  
  517. CagdSrfStruct *CnvrtBezier2BsplineSrf(CagdSrfStruct *Srf);
  518.  
  519. #if defined(__cplusplus) || defined(c_plusplus)
  520. }
  521. #endif
  522.  
  523. #endif /* CAGD_LIB_H */
  524.